Ext.define('DragonApp.view.pack.FilterBar', {
    extend: 'Ext.toolbar.Toolbar',
    xtype: 'pack-filter',

    controller: 'pack',

    items: [{
            xtype: 'radiogroup',
            fieldLabel: '筛选条件',
            defaultType: 'radiofield',
            itemId: 'conditions',

            defaults: {
                width: 130
            },
            items: [{
                boxLabel: '不限',
                name: 'pack_filter',
                inputValue: 'unlimited',
                checked: true
            }, {
                boxLabel: '类型',
                name: 'pack_filter',
                inputValue: 'type'
            }, {
                boxLabel: '品质',
                name: 'pack_filter',
                inputValue: 'quality'
            }],
            listeners: {

                change: {

                    fn: function() {

                        var QualityGroup = Ext.create('DragonApp.view.pack.filter.QualityGroup', {});
                        var TypeGroup = Ext.create('DragonApp.view.pack.filter.TypeGroup', {});

                        QualityGroup.setValue('0');
                        TypeGroup.setValue('0');

                        var grid = Ext.ComponentQuery.query('packgrid')[0];;

                        //清空细分

                        var filter_items = grid.queryById('filter-items');
                        filter_items.removeAll();

                        var store = Ext.data.StoreManager.lookup('jsonPPackStore');

                        var value = this.getValue().pack_filter;
                        switch (value) {
                            case 'unlimited':
                                store.clearFilter();
                                break;
                            case 'quality':
                                store.clearFilter();
                                filter_items.add(QualityGroup);
                                break;
                            case 'type':
                                store.clearFilter();
                                filter_items.add(TypeGroup);
                                break;
                        }
                    }
                }
            }
        },
        '->',
        {
            xtype: 'textfield',
            name: 'searchfield',
            itemId: 'search_field',
            emptyText: '请输入货币/道具名称',
            listeners: {
                specialKey: 'onTextFieldSpecialKeySearch',
                change: 'onTextFieldClear'
            }
        }, {
            xtype: 'button',
            itemId: 'search_btn',
            text: '搜索',
            reference: 'search',
            iconCls: 'fa fa-search fa-lg buttonIcon',
            listeners: {
                click: 'onSearch'
            }
        }
    ]
});